<template>
  <div>
    <!--mask-->
    <div class="mobile_mask" v-show="mobileMask" @click="close_mobile_agent"></div>

    <!--申请加盟模态框-->
    <div class="bg_fff mobile_agent_modal">
      <div class="consult_title"><p>联系我们</p><div class="consult_modal_close" @click="close_mobile_agent"></div></div>
      <div class="mobile_agent_modal_body">
        <div class="mobile_city_select">
          <select id="mobile_modal_province" name="mobile_modal_province" class="form-control"></select>
          <span>-</span>
          <select id="mobile_modal_city" name="mobile_modal_city" class="form-control"></select>
          <span>-</span>
          <select id="mobile_modal_cmbArea" class="form-control"></select>
        </div>
        <button type="button" class="bg_2577EF col_fff margin_top_16 mobile_agent_search" @click="mobile_search_agent">查询</button>

        <!--无加盟商-->
        <div class="mobile_no_agent" v-if="mobile_no_agent">
          <p v-if="mobile_no_search_agent">请选择位置信息后查询加盟商信息</p>
          <div class="mobile_no_agent_txt" v-else>
            <p>您查询的地区尚无加盟商信息，</p>
            <p>如有疑问可拨打咨询电话</p>
            <p><a href="tel://021-67680297">021-67680297</a></p>
          </div>
        </div>

        <!--加盟商列表-->
        <ul class="margin_top_20 mobile_agent_list clear" v-else v-for="(item,index) in agent_arr" :key="index">
          <li>
            <div class="mobile_agent_enterprise clear">
              <div class="float_left mobile_agent_logo"></div>
              <div class="float_left font_14 text-left multiline mobile_agent_name">
                {{item.title}}
              </div>
              <div class="margin_top_10 font_12 col_666">
                <p class="single_line">地址:<span>{{item.address}}</span></p>
                <p class="margin_0">电话：<span>{{item.phone}}</span><span class="margin_left_20">{{item.telephone}}</span></p>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
  import sity_address from '@/js/city-address.js'
  //每个子组价都需要抛出
  export default{
    name: "mobile_agent_modal",
    methods: {
      /**
       * PC端
       * 点击查询代理商
       * **/
      search_agent_btn(){
        let that = this;
        that.agent_arr = [];
        //获取省，市，县
        let modal_province = $("#modal_province option:selected").text();
        let modal_city = $("#modal_city option:selected").text();
        let modal_cmbArea = $("#modal_cmbArea option:selected").text();
        let modal_select_str = modal_province + modal_city + modal_cmbArea;
        that.base.ajax_get('/site/new/join/shop?select=' + modal_select_str, function (data) {
          if (data.status == 0) {
            //如果有数据隐藏无数据提示信息
            if (data.detail.length !== 0) {
              //有加盟商信息，则隐藏无加盟商提示
              that.no_agent = false;
              that.agent_arr = data.detail;
            } else {
              //无加盟商信息，则显示无加盟商提示。和显示未查询到
              that.no_query = false;
              that.no_agent = true;
            }
          } else {
            alert(data.detail)
          }
        });
      },

      /**
       *移动端
       * 点击关闭查询代理商
       * **/
      close_mobile_agent(){
          let that = this;
          that.sub_consult = false;
          $(".mobile_agent_modal").animate({"height":0},'500','swing');
          that.$emit('succ',false);
      },

      /**
       * 移动端
       * 点击搜索查询加盟商
       * **/
      mobile_search_agent(){
        let that = this;
        that.agent_arr = [];

        //获取省，市，县
        let modal_province = $("#mobile_modal_province option:selected").text();
        let modal_city = $("#mobile_modal_city option:selected").text();
        let modal_cmbArea = $("#mobile_modal_cmbArea option:selected").text();
        let modal_select_str = modal_province + modal_city + modal_cmbArea;
        that.base.ajax_get('/site/new/join/shop?select=' + modal_select_str, function (data) {
          if (data.status == 0) {
            //如果有数据隐藏无数据提示信息
            if (data.detail.length !== 0) {
              //有加盟商信息，则隐藏无加盟商提示
              that.mobile_no_agent = false;
              that.agent_arr = data.detail;
            } else {
              //无加盟商信息，则显示无加盟商提示。和显示未查询到
              that.mobile_no_search_agent = false;
            }
          } else {
            alert(data.detail)
          }
        });


      }
    },
    //在模板渲染之后调用
    mounted () {
      /**
       * 三级联动插件
       * **/
      sity_address.address('mobile_modal_province', 'mobile_modal_city', 'mobile_modal_cmbArea');
    },
    props:{
        mobileMask:Boolean//定义传值类型
    },
    data () {
      return {
        mobile_no_agent: true,
        mobile_no_search_agent: true,
        agent_arr:[]
      }
    }
  }
</script>

<style scoped>
  ::-webkit-scrollbar { /*隐藏滚轮*/
    display: none;
  }

  .mobile_agent_modal {
    position: fixed;
    bottom: 0px;
    left: 0;
    width: 100%;
    height: 0;
    z-index: 999;
  }
  .mobile_agent_modal_body{
    padding: 20px 15px;
  }
  .mobile_city_select select{
    display: inline-block;
    padding: 6px;
    width: calc(33.333% - 16px);
  }
  .mobile_city_select span{
    width: 15px;
    display: inline-block;
  }
  .mobile_agent_search{
    width: 100%;
    height: 36px;
    line-height: 36px;
    border-radius: 2px;
  }
  .mobile_agent_list{
    padding: 10px;
    width: 100%;
    border-radius: 4px;
    border: 1px solid #999999;
    height: 300px;
    overflow-y: scroll;
  }
  .mobile_agent_list li{
    width: 100%;
    margin-top: 20px;
    box-shadow: 0px 2px 8px rgba(34, 35, 36, 0.15);
    border-radius: 2px;
    padding: 10px;
  }
  .mobile_agent_list li:first-child{
    margin-top: 0;
  }
  .mobile_agent_enterprise {
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }
  .mobile_agent_logo{
    width: 40px;
    height: 40px;
    background-image: url("http://image.xuemei99.com/company_icon_jiameng.png");
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
  }
  .mobile_agent_name{
    width: calc(100% - 40px);
    padding-left: 10px;
  }
  .mobile_no_agent{
    height: 300px;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
  }
  .mobile_no_agent p{
    width: 100%;
  }
  .mobile_no_agent_txt{
    width: 100%;
  }

</style>
